package SwingView.Announcement;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import JDBC.InstructorAnnouncementActivities;
import JDBC.StudentAnnouncementActivities;
import SwingController.CmsPresenter;
import SwingModel.CmsAnnouncement;
import SwingModel.CmsInstructor;
import SwingModel.CmsUser;
import SwingView.CmsMainView;
import SwingView.CmsPageSelector.CmsPage;
import SwingView.Lecture.CmsCPInstructorLecture;
import SwingView.Lecture.CmsCPStudentLecture;

public class ALAnnouncement implements ActionListener{

	private final CmsMainView mainView;
	private final CmsUser user;
	private final CmsCPStudentAnnouncement studentPage;
	private final CmsCPInstructorAnnouncement instructorPage;

	//---------------------------------------------------------
	//CONSTRUCTOR:
	//---------------------------------------------------------		
	public ALAnnouncement(CmsMainView mainView, CmsUser user){
		this.mainView = mainView;
		this.user = user;
		this.studentPage = mainView.getContentPanel().getAnmStudentPage();
		this.instructorPage = mainView.getContentPanel().getAnmInstructorPage();
	}

	//---------------------------------------------------------
	//PERFORMING ACTION:
	//---------------------------------------------------------		
	@Override
	public void actionPerformed(ActionEvent e){
		
		List<CmsAnnouncement> listOfAnnouncement;
		
		//.....................................................
		//INSTRUCTOR CASE:
		if (user instanceof CmsInstructor){
			listOfAnnouncement = InstructorAnnouncementActivities.getListOfAnnouncement(CmsPresenter.user.getUsername()
					, CmsPresenter.user.getSelectedCourse().getCourseID());
			
			//Highlight the Lecture Button
			mainView.displayAnnouncementInstructorPage(listOfAnnouncement);
		}
		
		//.....................................................
		//STUDENT CASE:
		else{//Student case
			listOfAnnouncement = StudentAnnouncementActivities.getListOfAnnouncement(CmsPresenter.user.getUsername()
					, CmsPresenter.user.getSelectedCourse().getCourseID());
			
			//Highlight the Lecture Button
			mainView.displayAnnouncementStudentPage(listOfAnnouncement);
		}
		
	}
}
